A vector is a sequence of objects of the same class.
Arrays and matrices are special type of vectors with dimensions.
Matrices have 2 dimensions.
Arrays could have higher dimensions.
Fundamentals of R
Vectors
Lists
Superficially for users, a list can contain objects of different classes.
Like vectors, a list can also be converted to list-matrix or list-array by defining dimensions.
data.frame and tibble are two S3 object-oriented objects that are created upon list for tabular data.
Fundamentals of R
Vectors
Fundamentals of R
Creation
Function vector(mode, length) can be used to initialize a vector of specific data type with defined length.
More commonly, function c (short for concatenate) can be used to create vectors.
cbind and rbind are functions can bind vectors to a matrix. Function matrix(data_vector, nrow, ncol) also can be used to create a matrix, and array(data_vector, dim) for array.
Anything can feed in function list to create a list, the same as data.frame.
is.xxx(x) and as.xxx(x) also works for vector, matrix, array, list, and data.frame.
Fundamentals of R
Atrributes
Any objects have attributes. If nothing is set, the attributes of an object is NULL. Some common attributes include:
names/dimnames/rownames/colnames
Overall length, and more specifically dim for matrix and array. Resetting dim attribute can convert a vector to matrix/array or reconstruct a matrix/array.
I’ll leave you with a short homework to review what we’ve learned.
Now, let’s get back to your package.
Installing and using packages
http://r-pkgs.had.co.nz/package.html
Package structure
General common parts of a package.
Package structure
Package structure
You main tasks for the assignment package are update:
DESCIPTION file to incorporate updated info (e.g. your package version)
.R files in the R/ folder (e.g. write functions)
.Rmd files in the vignettes/ folder (main files for assignments)
Add a function to your package
Why we need functions and packages?
Reuse -> Reproducibility
Add a my_number_checker function to your package (let me show you first)
Add a vignette to introduce the function
Use usethis::use_vignette("vignette_name")
Update and install the package locally.
Git add and commit all updates.
Git branching
Create a new branch named test and push to the remote repo
git branch test (create a new branch)
git checkout test (switch to the new branch)
git push origin test (push the new branch to GitHub)